<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教师评教</title>
    <link rel="stylesheet" href="/css/layui.css">
</head>
 <body>
  <div style="width: 800px;margin: 0 auto;position: absolute;left: 5%;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;text-align: center">
        <legend>教师评教</legend>
    </fieldset>

    <form class="layui-form" action="" lay-filter="addStuScore">

        <div class="layui-form-item">
            <label class="layui-form-label">科目</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="subjectId" id="subjectId">
                    <option value="">请选择科目</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">教师</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="teacherId"  lay-verify="required" id="teacherId" lay-filter="teacherId" lay-search>
                    <option value="">请选择</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">评分</label>
            <div class="layui-input-inline" style="width: 200px">
                <select name="evaluateId">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item" style="text-align: center">
            <button  class="layui-btn" lay-submit lay-filter="doSubmit">提交</button>
            <input type="reset" class="layui-btn" value="重置">
        </div>
    </form>
  </div>
 </body>
<script src="/layui.js"></script>
<script src="/js/jquery-1.8.3.js"></script>
<script>

    layui.use(["form","layer" ,"element"],function () {
        let form = layui.form;
        let layer = layui.layer;
        let element = layui.element;

        form.on("submit(doSubmit)", function (data) {
            $.post("/student/addComment", data.field, function (res) {
                if (res.success == "true") {
                    layer.alert("提交成功！", {icon: 6, time: 2000});
                    setTimeout(function () {
                        layer.closeAll();
                    }, 1000 * 1.5)
                } else {
                    layer.alert(res.msg, {icon: 5, time: 2000})
                }

            });
            return false;
        });

        //用ajax查询科目
        $.get("/student/querySubject",function (res) {
            let selectInfo="";
            //循环遍历集合
            for (let i = 0; i <res.data.length ; i++) {
                selectInfo +="<option value='"+res.data[i].id+"'>"+res.data[i].subjectName+"</option>"
            }
            //追加到下拉框列表中
            $("[name='subjectId']").append(selectInfo);

            //更新渲染select下拉框
            form.render("select");
        },"json");

        //用ajax根据科目查询教师
        $.get("/student/queryTeacher",function (res) {
            let selectInfo="";
            //循环遍历集合
            for (let i = 0; i <res.data.length ; i++) {
                selectInfo +="<option value='"+res.data[i].id+"'>"+res.data[i].teachersName+"</option>"
            }
            //追加到下拉框列表中
            $("[name='teacherId']").append(selectInfo);

            //更新渲染select下拉框
            form.render("select");
        },"json");

        // form.on('select(teacherId)', function (data) {
        //     $.post("/student/queryTeacher", data.field, function (res) {
        //         let selectInfo="";
        //             //循环遍历集合
        //             for (let i = 0; i <res.data.length ; i++) {
        //                 selectInfo +="<option value='"+res.data[i].id+"'>"+res.data[i].teachersName+"</option>"
        //             }
        //             //追加到下拉框列表中
        //             $("[name='teacherId']").append(selectInfo);
        //
        //             //更新渲染select下拉框
        //             form.render("select");
        //     },"json");
        // });

        // form.on('select(teacherId)', function (data) {
        //     let subjectId = data.value;
        //     let selectInfo = '';
        //     if (subjectId == '') {
        //         $("#teacherId").html(s);
        //         form.render('select');
        //     } else {
        //         $.ajax({
        //             async: false,
        //             type: "POST", //提交方式
        //             url: '/student/queryTeacher',//路径
        //             data: {
        //                 subjectId: subjectId
        //             },
        //             success: function (res) {
        //                 //循环遍历集合
        //                     for (let i = 0; i <res.data.length ; i++) {
        //                         selectInfo +="<option value='"+res.data[i].id+"'>"+res.data[i].teachersName+"</option>"
        //                     }
        //                     //追加到下拉框列表中
        //                     $("[name='teacherId']").append(selectInfo);
        //
        //                     //更新渲染select下拉框
        //                     form.render("select");
        //                 // },"json");
        //             }
        //         });
        //     }
        // });

        //用ajax查询评价等级
        $.get("/student/queryEvaluate", function (res) {
            let selectInfo = "";
            //循环遍历集合
            for (let i = 0; i < res.data.length; i++) {
                selectInfo += "<option value='" + res.data[i].id + "'>" + res.data[i].rank + "</option>"
            }
            //追加到下拉框列表中
            $("[name='evaluateId']").append(selectInfo);

            //更新渲染select下拉框
            form.render("select");
        }, "json");

    });

</script>
</html>